package com.aitaoxue.palx.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import butterknife.ButterKnife;
import butterknife.InjectView;

import com.aitaoxue.palx.R;
import com.aitaoxue.palx.api.ApiHttpClient;
import com.aitaoxue.palx.base.ListBaseAdapter;
import com.aitaoxue.palx.bean.Customer;
import com.aitaoxue.palx.widget.CircleImageView;
import com.nostra13.universalimageloader.core.ImageLoader;

public class MyCustomerAdapter extends ListBaseAdapter {

	@Override
	protected View getRealView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null || convertView.getTag() == null) {
			convertView = LayoutInflater.from(parent.getContext()).inflate(
					R.layout.list_cell_customer, null);
			viewHolder = new ViewHolder(convertView);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		Customer customer = (Customer) _data.get(position);

		viewHolder.first
				.setText(customer.getUser_name() + "/"
						+ customer.getGood_kind_name() + "/"
						+ customer.getUser_phone());
		viewHolder.address.setText(customer.getUser_addr_address());
		viewHolder.num.setText("总课时:" + customer.getOrder_num());

		ImageLoader.getInstance().displayImage(
				ApiHttpClient.HEADER_PREFIX + customer.getUser_head_thumb(),
				viewHolder.header);

		return convertView;
	}

	class ViewHolder {

		@InjectView(R.id.header)
		CircleImageView header;
		@InjectView(R.id.first)
		TextView first;
		@InjectView(R.id.second)
		TextView address;
		@InjectView(R.id.third)
		TextView num;

		public ViewHolder(View view) {
			ButterKnife.inject(this, view);
		}

	}

}
